<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./jQuery.min.js"></script>
  </head>

  <body>
    <button class="btnGET">GET</button>
    <button class="btnPOST">POST</button>

    <script>
      $(function () {
        $(".btnGET").on("click", function () {
          $.ajax({
            type: "GET",
            url: "http://127.0.0.1/api/get",
            data: { name: "雪中悍刀行", age: '烽火戏诸侯' },
            success: function (res) {
              console.log(res);
            },
          });
        });
        // 2. 测试POST接口
        $(".btnPOST").on("click", function () {
          $.ajax({
            type: "POST",
            url: "http://127.0.0.1/api/post",
            data: { bookname: "水浒传", author: "施耐庵" },
            success: function (res) {
              console.log(res);
            },
          });
        });
      });
    </script>
  </body>
</html>
